<template>
  <div>
    <div>
      <van-search
        v-model="searchvalue"
        shape="round"
        placeholder="请输入搜索内容"
        show-action
        class="search"
      >
        <template #right-icon>
          <van-button
            text="搜索"
            @click="changetab"
            class="searchbtn"
          ></van-button>
        </template>
        <template #action>
          <div class="more">...</div>
        </template>
      </van-search>
    </div>
    <van-row class="row">
      <van-col span="6">
        <div class="four-box" @click="gotolink('marketorder')">
          <icon-svg
            icon-class="market_order"
            icon-color="#FFFFFF"
            class="boxicon"
          ></icon-svg>
          <div class="linktitle">我的订单</div>
        </div>
      </van-col>
      <van-col span="6">
        <div class="four-box" @click="gotolink('marketcart')">
          <icon-svg
            icon-class="shoppingcart"
            icon-color="#FFFFFF"
            class="boxicon"
          ></icon-svg>
          <div class="linktitle">购物车</div>
        </div>
      </van-col>
      <van-col span="6">
        <div class="four-box" @click="gotolink('marketevaluate')">
          <icon-svg
            icon-class="market_comment"
            icon-color="#FFFFFF"
            class="boxicon"
          ></icon-svg>
          <div class="linktitle">我的评价</div>
        </div>
      </van-col>
      <van-col span="6">
        <div class="four-box" @click="gotolink('refundpage')">
          <icon-svg
            icon-class="tuikuan"
            icon-color="#FFFFFF"
            class="boxicon"
          ></icon-svg>
          <div class="linktitle">退款售后</div>
        </div>
      </van-col>
    </van-row>
    <van-pull-refresh
      v-model="isLoading"
      @refresh="onRefresh"
      class="pullrefresh"
    >
      <div style="display: flex; justify-content: center; margin: 0 auto">
        <van-grid :gutter="12" :column-num="2" class="gridbox">
          <div
            class="mgoodbox"
            v-for="item in mgoodlist"
            :key="item.id"
            @click="goodsdetail(item)"
          >
            <div class="mgoodimgbox">
              <img v-lazy="item.image" alt="" class="mgoodimg" />
            </div>
            <div class="mgoodinfo">
              <div class="mgoodname">
                {{ item.name }}
              </div>
              <div class="mgoodprice">￥{{ item.price }}/{{ item.unit }}</div>
            </div>
          </div>
        </van-grid>
      </div>
    </van-pull-refresh>
    <div style="padding-bottom: calc(50px + env(safe-area-inset-bottom))" />
  </div>
</template>

<script>
import { getshopgoods } from "@/http/request.js";
export default {
  data() {
    return {
      activeName: "money",
      searchvalue: "",
      mgoodlist: [],
      isLoading: false,
      active: "all",
    };
  },
  methods: {
    gotolink(path) {
      this.$router.push(path);
    },
    goodsdetail(item) {
      this.$router.push({
        name: "GoodsDetail",
        params: {
          goodsinfo: JSON.stringify(item),
        },
      });
    },
    changetab() {},
    filtergoods() {},
    onRefresh() {
      setTimeout(() => {
        this.isLoading = false;
      }, 1000);
    },
    changefilter() {
      // if(value == "all"){
      // }else if(value == "new"){
      // }else if(value == "sale"){
      // }else if(value == "price"){
      // }
    },
    initdata() {
      getshopgoods().then((res) => {
        this.mgoodlist = res.data;
      });
    },
  },
  mounted() {
    this.initdata();
  },
};
</script>

<style scoped>
.search {
  background-color: transparent !important;
  padding-left: 20px;
  padding-bottom: 0;
}

::v-deep .van-search__content--round {
  /* 勿删，搜索框外边框 */
  border: 1px solid #5f94fe;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 30px;
  border-radius: 12px;
}

.more {
  font-size: 50px;
  color: rgb(80, 80, 80);
  margin-left: 10px;
  margin-right: 10px;
  margin-bottom: 30px;
  width: 30px;
}

.searchbtn {
  width: 50px;
  height: 25px;
  margin-bottom: 5px;
  margin-right: -5px;
  font-size: 14px;
  color: #fff;
  border-radius: 8px;
  padding: 0 5px;
  background-color: #5f94fe;
}

.groundtab :deep(.van-tab__text--ellipsis) {
  font-size: 20px;
}
.pullrefresh {
  height: 100%;
  background-color: #f2f3f5;
  margin: 0 auto;
  display: flex;
  justify-content: center;
}

.row {
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.linktitle {
  font-size: 14px;
  font-weight: 550;
}
.four-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 60px;
  font-size: 14px;
}
.boxicon {
  width: 35px;
  height: 35px;
}

.gridbox {
  justify-content: center;
  padding: 0 !important;
}
.gridbox > :last-child {
  margin-right: auto;
}
.mgoodbox {
  width: 42%;
  margin: 5px;
  padding: 10px;
  background-color: #fff;
  border-radius: 8px;
}

.mgoodimgbox .mgoodimg {
  width: 100%;
  height: 150px;
}
.mgoodimg img{
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.mgoodinfo {
  display: flex;
  flex-direction: column;
}

.mgoodinfo .mgoodname {
  font-size: 18px;
  font-weight: 550;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  -webkit-line-clamp: 1;
}

.mgoodinfo .mgoodprice {
  font-size: 18px;
  font-weight: 550;
  color: #ff4d4f;
}
</style>